


<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>torch.nn.modules.pooling &mdash; PyTorch master documentation</title>
  

  
  
  
  
    <link rel="canonical" href="https://pytorch.org/docs/stable/_modules/torch/nn/modules/pooling.html"/>
  

  

  
  
    

  

  <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  <!-- <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" /> -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/css/jit.css" type="text/css" />
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/katex-math.css" type="text/css" />
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" /> 

  
  <script src="../../../../_static/js/modernizr.min.js"></script>

  <!-- Preload the theme fonts -->

<link rel="preload" href="../../../../_static/fonts/FreightSans/freight-sans-book.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../../../../_static/fonts/FreightSans/freight-sans-medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../../../../_static/fonts/IBMPlexMono/IBMPlexMono-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../../../../_static/fonts/FreightSans/freight-sans-bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../../../../_static/fonts/FreightSans/freight-sans-medium-italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../../../../_static/fonts/IBMPlexMono/IBMPlexMono-SemiBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">

<!-- Preload the katex fonts -->

<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Main-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size1-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size3-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Caligraphic-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
</head>

<div class="container-fluid header-holder tutorials-header" id="header-holder">
  <div class="container">
    <div class="header-container">
      <a class="header-logo" href="https://pytorch.org/" aria-label="PyTorch"></a>

      <div class="main-menu">
        <ul>
          <li>
            <a href="https://pytorch.org/get-started">Get Started</a>
          </li>

          <li>
            <div class="ecosystem-dropdown">
              <a id="dropdownMenuButton" data-toggle="ecosystem-dropdown">
                Ecosystem
              </a>
              <div class="ecosystem-dropdown-menu">
                <a class="nav-dropdown-item" href="https://pytorch.org/hub"">
                  <span class=dropdown-title>Models (Beta)</span>
                  <p>Discover, publish, and reuse pre-trained models</p>
                </a>
                <a class="nav-dropdown-item" href="https://pytorch.org/ecosystem">
                  <span class=dropdown-title>Tools & Libraries</span>
                  <p>Explore the ecosystem of tools and libraries</p>
                </a>
              </div>
            </div>
          </li>

          <li>
            <a href="https://pytorch.org/mobile">Mobile</a>
          </li>

          <li>
            <a href="https://pytorch.org/blog/">Blog</a>
          </li>

          <li>
            <a href="https://pytorch.org/tutorials">Tutorials</a>
          </li>

          <li class="active">
            <a href="https://pytorch.org/docs/stable/index.html">Docs</a>
          </li>

          <li>
            <div class="resources-dropdown">
              <a id="resourcesDropdownButton" data-toggle="resources-dropdown">
                Resources
              </a>
              <div class="resources-dropdown-menu">
                <a class="nav-dropdown-item" href="https://pytorch.org/resources"">
                  <span class=dropdown-title>Developer Resources</span>
                  <p>Find resources and get questions answered</p>
                </a>
                <a class="nav-dropdown-item" href="https://pytorch.org/features">
                  <span class=dropdown-title>About</span>
                  <p>Learn about PyTorch’s features and capabilities</p>
                </a>
              </div>
            </div>
          </li>

          <li>
            <a href="https://github.com/pytorch/pytorch">Github</a>
          </li>
        </ul>
      </div>

      <a class="main-menu-open-button" href="#" data-behavior="open-mobile-menu"></a>
    </div>

  </div>
</div>


<body class="pytorch-body">

   

    

    <div class="table-of-contents-link-wrapper">
      <span>Table of Contents</span>
      <a href="#" class="toggle-table-of-contents" data-behavior="toggle-table-of-contents"></a>
    </div>

    <nav data-toggle="wy-nav-shift" class="pytorch-left-menu" id="pytorch-left-menu">
      <div class="pytorch-side-scroll">
        <div class="pytorch-menu pytorch-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          <div class="pytorch-left-menu-search">
            

            
              
              
                <div class="version">
                  master (1.5.0 )
                </div>
              
            

            


  


<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search Docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

            
          </div>

          
<div>
  <a style="color:#F05732" href="https://pytorch.org/docs/stable/_modules/torch/nn/modules/pooling.html">
    You are viewing unstable developer preview docs.
    Click here to view docs for latest stable release.
  </a>
</div>

            
            
              
            
            
              <p class="caption"><span class="caption-text">Notes</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/amp_examples.html">Automatic Mixed Precision examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/autograd.html">Autograd mechanics</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/broadcasting.html">Broadcasting semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/cpu_threading_torchscript_inference.html">CPU threading and TorchScript inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/cuda.html">CUDA semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/ddp.html">Distributed Data Parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/extending.html">Extending PyTorch</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/faq.html">Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/large_scale_deployments.html">Features for large-scale deployments</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/multiprocessing.html">Multiprocessing best practices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/randomness.html">Reproducibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/serialization.html">Serialization semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../notes/windows.html">Windows FAQ</a></li>
</ul>
<p class="caption"><span class="caption-text">Language Bindings</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/cppdocs/">C++ API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../packages.html">Javadoc</a></li>
</ul>
<p class="caption"><span class="caption-text">Python API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../torch.html">torch</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../nn.html">torch.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../nn.functional.html">torch.nn.functional</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../tensors.html">torch.Tensor</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../tensor_attributes.html">Tensor Attributes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../tensor_view.html">Tensor Views</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../autograd.html">torch.autograd</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../cuda.html">torch.cuda</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../amp.html">torch.cuda.amp</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../distributed.html">torch.distributed</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../distributions.html">torch.distributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../hub.html">torch.hub</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../jit.html">torch.jit</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../nn.init.html">torch.nn.init</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../onnx.html">torch.onnx</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../optim.html">torch.optim</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../quantization.html">Quantization</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../rpc/index.html">Distributed RPC Framework</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../random.html">torch.random</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../sparse.html">torch.sparse</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../storage.html">torch.Storage</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../bottleneck.html">torch.utils.bottleneck</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../checkpoint.html">torch.utils.checkpoint</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../cpp_extension.html">torch.utils.cpp_extension</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../data.html">torch.utils.data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../dlpack.html">torch.utils.dlpack</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../model_zoo.html">torch.utils.model_zoo</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../tensorboard.html">torch.utils.tensorboard</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../type_info.html">Type Info</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../named_tensor.html">Named Tensors</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../name_inference.html">Named Tensors operator coverage</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../__config__.html">torch.__config__</a></li>
</ul>
<p class="caption"><span class="caption-text">Libraries</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/audio">torchaudio</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/text">torchtext</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/elastic/">TorchElastic</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/serve">TorchServe</a></li>
<li class="toctree-l1"><a class="reference external" href="http://pytorch.org/xla/">PyTorch on XLA Devices</a></li>
</ul>
<p class="caption"><span class="caption-text">Community</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../community/contribution_guide.html">PyTorch Contribution Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../community/governance.html">PyTorch Governance</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../community/persons_of_interest.html">PyTorch Governance | Persons of Interest</a></li>
</ul>

            
          

        </div>
      </div>
    </nav>

    <div class="pytorch-container">
      <div class="pytorch-page-level-bar" id="pytorch-page-level-bar">
        <div class="pytorch-breadcrumbs-wrapper">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="pytorch-breadcrumbs">
    
      <li>
        <a href="../../../../index.html">
          
            Docs
          
        </a> &gt;
      </li>

        
          <li><a href="../../../index.html">Module code</a> &gt;</li>
        
          <li><a href="../../../torch.html">torch</a> &gt;</li>
        
      <li>torch.nn.modules.pooling</li>
    
    
      <li class="pytorch-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
</div>
        </div>

        <div class="pytorch-shortcuts-wrapper" id="pytorch-shortcuts-wrapper">
          Shortcuts
        </div>
      </div>

      <section data-toggle="wy-nav-shift" id="pytorch-content-wrap" class="pytorch-content-wrap">
        <div class="pytorch-content-left">

        
          
          <div class="rst-content">
          
            <div role="main" class="main-content" itemscope="itemscope" itemtype="http://schema.org/Article">
             <article itemprop="articleBody" id="pytorch-article" class="pytorch-article">
              
  <h1>Source code for torch.nn.modules.pooling</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">absolute_import</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">division</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">unicode_literals</span>

<span class="kn">from</span> <span class="nn">.module</span> <span class="kn">import</span> <span class="n">Module</span>
<span class="kn">from</span> <span class="nn">.utils</span> <span class="kn">import</span> <span class="n">_single</span><span class="p">,</span> <span class="n">_pair</span><span class="p">,</span> <span class="n">_triple</span>
<span class="kn">from</span> <span class="nn">..</span> <span class="kn">import</span> <span class="n">functional</span> <span class="k">as</span> <span class="n">F</span>


<span class="k">class</span> <span class="nc">_MaxPoolNd</span><span class="p">(</span><span class="n">Module</span><span class="p">):</span>
    <span class="n">__constants__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;kernel_size&#39;</span><span class="p">,</span> <span class="s1">&#39;stride&#39;</span><span class="p">,</span> <span class="s1">&#39;padding&#39;</span><span class="p">,</span> <span class="s1">&#39;dilation&#39;</span><span class="p">,</span>
                     <span class="s1">&#39;return_indices&#39;</span><span class="p">,</span> <span class="s1">&#39;ceil_mode&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">stride</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">padding</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">dilation</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                 <span class="n">return_indices</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">ceil_mode</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">_MaxPoolNd</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">kernel_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stride</span> <span class="o">=</span> <span class="n">stride</span> <span class="ow">or</span> <span class="n">kernel_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="n">padding</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dilation</span> <span class="o">=</span> <span class="n">dilation</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span> <span class="o">=</span> <span class="n">return_indices</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span> <span class="o">=</span> <span class="n">ceil_mode</span>

    <span class="k">def</span> <span class="nf">extra_repr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;kernel_size=</span><span class="si">{kernel_size}</span><span class="s1">, stride=</span><span class="si">{stride}</span><span class="s1">, padding=</span><span class="si">{padding}</span><span class="s1">&#39;</span> \
            <span class="s1">&#39;, dilation=</span><span class="si">{dilation}</span><span class="s1">, ceil_mode=</span><span class="si">{ceil_mode}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">)</span>


<div class="viewcode-block" id="MaxPool1d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.MaxPool1d">[docs]</a><span class="k">class</span> <span class="nc">MaxPool1d</span><span class="p">(</span><span class="n">_MaxPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 1D max pooling over an input signal composed of several input</span>
<span class="sd">    planes.</span>

<span class="sd">    In the simplest case, the output value of the layer with input size :math:`(N, C, L)`</span>
<span class="sd">    and output :math:`(N, C, L_{out})` can be precisely described as:</span>

<span class="sd">    .. math::</span>
<span class="sd">        out(N_i, C_j, k) = \max_{m=0, \ldots, \text{kernel\_size} - 1}</span>
<span class="sd">                input(N_i, C_j, stride \times k + m)</span>

<span class="sd">    If :attr:`padding` is non-zero, then the input is implicitly zero-padded on both sides</span>
<span class="sd">    for :attr:`padding` number of points. :attr:`dilation` controls the spacing between the kernel points.</span>
<span class="sd">    It is harder to describe, but this `link`_ has a nice visualization of what :attr:`dilation` does.</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: the size of the window to take a max over</span>
<span class="sd">        stride: the stride of the window. Default value is :attr:`kernel_size`</span>
<span class="sd">        padding: implicit zero padding to be added on both sides</span>
<span class="sd">        dilation: a parameter that controls the stride of elements in the window</span>
<span class="sd">        return_indices: if ``True``, will return the max indices along with the outputs.</span>
<span class="sd">                        Useful for :class:`torch.nn.MaxUnpool1d` later</span>
<span class="sd">        ceil_mode: when True, will use `ceil` instead of `floor` to compute the output shape</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, L_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, L_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              L_{out} = \left\lfloor \frac{L_{in} + 2 \times \text{padding} - \text{dilation}</span>
<span class="sd">                    \times (\text{kernel\_size} - 1) - 1}{\text{stride}} + 1\right\rfloor</span>

<span class="sd">    Examples::</span>

<span class="sd">        &gt;&gt;&gt; # pool of size=3, stride=2</span>
<span class="sd">        &gt;&gt;&gt; m = nn.MaxPool1d(3, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(20, 16, 50)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    .. _link:</span>
<span class="sd">        https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">max_pool1d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dilation</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span><span class="p">,</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span><span class="p">)</span></div>


<div class="viewcode-block" id="MaxPool2d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.MaxPool2d">[docs]</a><span class="k">class</span> <span class="nc">MaxPool2d</span><span class="p">(</span><span class="n">_MaxPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 2D max pooling over an input signal composed of several input</span>
<span class="sd">    planes.</span>

<span class="sd">    In the simplest case, the output value of the layer with input size :math:`(N, C, H, W)`,</span>
<span class="sd">    output :math:`(N, C, H_{out}, W_{out})` and :attr:`kernel_size` :math:`(kH, kW)`</span>
<span class="sd">    can be precisely described as:</span>

<span class="sd">    .. math::</span>
<span class="sd">        \begin{aligned}</span>
<span class="sd">            out(N_i, C_j, h, w) ={} &amp; \max_{m=0, \ldots, kH-1} \max_{n=0, \ldots, kW-1} \\</span>
<span class="sd">                                    &amp; \text{input}(N_i, C_j, \text{stride[0]} \times h + m,</span>
<span class="sd">                                                   \text{stride[1]} \times w + n)</span>
<span class="sd">        \end{aligned}</span>

<span class="sd">    If :attr:`padding` is non-zero, then the input is implicitly zero-padded on both sides</span>
<span class="sd">    for :attr:`padding` number of points. :attr:`dilation` controls the spacing between the kernel points.</span>
<span class="sd">    It is harder to describe, but this `link`_ has a nice visualization of what :attr:`dilation` does.</span>

<span class="sd">    The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding`, :attr:`dilation` can either be:</span>

<span class="sd">        - a single ``int`` -- in which case the same value is used for the height and width dimension</span>
<span class="sd">        - a ``tuple`` of two ints -- in which case, the first `int` is used for the height dimension,</span>
<span class="sd">          and the second `int` for the width dimension</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: the size of the window to take a max over</span>
<span class="sd">        stride: the stride of the window. Default value is :attr:`kernel_size`</span>
<span class="sd">        padding: implicit zero padding to be added on both sides</span>
<span class="sd">        dilation: a parameter that controls the stride of elements in the window</span>
<span class="sd">        return_indices: if ``True``, will return the max indices along with the outputs.</span>
<span class="sd">                        Useful for :class:`torch.nn.MaxUnpool2d` later</span>
<span class="sd">        ceil_mode: when True, will use `ceil` instead of `floor` to compute the output shape</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, H_{in}, W_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, H_{out}, W_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              H_{out} = \left\lfloor\frac{H_{in} + 2 * \text{padding[0]} - \text{dilation[0]}</span>
<span class="sd">                    \times (\text{kernel\_size[0]} - 1) - 1}{\text{stride[0]}} + 1\right\rfloor</span>

<span class="sd">          .. math::</span>
<span class="sd">              W_{out} = \left\lfloor\frac{W_{in} + 2 * \text{padding[1]} - \text{dilation[1]}</span>
<span class="sd">                    \times (\text{kernel\_size[1]} - 1) - 1}{\text{stride[1]}} + 1\right\rfloor</span>

<span class="sd">    Examples::</span>

<span class="sd">        &gt;&gt;&gt; # pool of square window of size=3, stride=2</span>
<span class="sd">        &gt;&gt;&gt; m = nn.MaxPool2d(3, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; # pool of non-square window</span>
<span class="sd">        &gt;&gt;&gt; m = nn.MaxPool2d((3, 2), stride=(2, 1))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(20, 16, 50, 32)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    .. _link:</span>
<span class="sd">        https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">max_pool2d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dilation</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span><span class="p">,</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span><span class="p">)</span></div>


<div class="viewcode-block" id="MaxPool3d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.MaxPool3d">[docs]</a><span class="k">class</span> <span class="nc">MaxPool3d</span><span class="p">(</span><span class="n">_MaxPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 3D max pooling over an input signal composed of several input</span>
<span class="sd">    planes.</span>

<span class="sd">    In the simplest case, the output value of the layer with input size :math:`(N, C, D, H, W)`,</span>
<span class="sd">    output :math:`(N, C, D_{out}, H_{out}, W_{out})` and :attr:`kernel_size` :math:`(kD, kH, kW)`</span>
<span class="sd">    can be precisely described as:</span>

<span class="sd">    .. math::</span>
<span class="sd">        \begin{aligned}</span>
<span class="sd">            \text{out}(N_i, C_j, d, h, w) ={} &amp; \max_{k=0, \ldots, kD-1} \max_{m=0, \ldots, kH-1} \max_{n=0, \ldots, kW-1} \\</span>
<span class="sd">                                              &amp; \text{input}(N_i, C_j, \text{stride[0]} \times d + k,</span>
<span class="sd">                                                             \text{stride[1]} \times h + m, \text{stride[2]} \times w + n)</span>
<span class="sd">        \end{aligned}</span>

<span class="sd">    If :attr:`padding` is non-zero, then the input is implicitly zero-padded on both sides</span>
<span class="sd">    for :attr:`padding` number of points. :attr:`dilation` controls the spacing between the kernel points.</span>
<span class="sd">    It is harder to describe, but this `link`_ has a nice visualization of what :attr:`dilation` does.</span>

<span class="sd">    The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding`, :attr:`dilation` can either be:</span>

<span class="sd">        - a single ``int`` -- in which case the same value is used for the depth, height and width dimension</span>
<span class="sd">        - a ``tuple`` of three ints -- in which case, the first `int` is used for the depth dimension,</span>
<span class="sd">          the second `int` for the height dimension and the third `int` for the width dimension</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: the size of the window to take a max over</span>
<span class="sd">        stride: the stride of the window. Default value is :attr:`kernel_size`</span>
<span class="sd">        padding: implicit zero padding to be added on all three sides</span>
<span class="sd">        dilation: a parameter that controls the stride of elements in the window</span>
<span class="sd">        return_indices: if ``True``, will return the max indices along with the outputs.</span>
<span class="sd">                        Useful for :class:`torch.nn.MaxUnpool3d` later</span>
<span class="sd">        ceil_mode: when True, will use `ceil` instead of `floor` to compute the output shape</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, D_{in}, H_{in}, W_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, D_{out}, H_{out}, W_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              D_{out} = \left\lfloor\frac{D_{in} + 2 \times \text{padding}[0] - \text{dilation}[0] \times</span>
<span class="sd">                (\text{kernel\_size}[0] - 1) - 1}{\text{stride}[0]} + 1\right\rfloor</span>

<span class="sd">          .. math::</span>
<span class="sd">              H_{out} = \left\lfloor\frac{H_{in} + 2 \times \text{padding}[1] - \text{dilation}[1] \times</span>
<span class="sd">                (\text{kernel\_size}[1] - 1) - 1}{\text{stride}[1]} + 1\right\rfloor</span>

<span class="sd">          .. math::</span>
<span class="sd">              W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] - \text{dilation}[2] \times</span>
<span class="sd">                (\text{kernel\_size}[2] - 1) - 1}{\text{stride}[2]} + 1\right\rfloor</span>

<span class="sd">    Examples::</span>

<span class="sd">        &gt;&gt;&gt; # pool of square window of size=3, stride=2</span>
<span class="sd">        &gt;&gt;&gt; m = nn.MaxPool3d(3, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; # pool of non-square window</span>
<span class="sd">        &gt;&gt;&gt; m = nn.MaxPool3d((3, 2, 2), stride=(2, 1, 2))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(20, 16, 50,44, 31)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    .. _link:</span>
<span class="sd">        https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md</span>
<span class="sd">    &quot;&quot;&quot;</span>  <span class="c1"># noqa: E501</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">max_pool3d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dilation</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span><span class="p">,</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span><span class="p">)</span></div>


<span class="k">class</span> <span class="nc">_MaxUnpoolNd</span><span class="p">(</span><span class="n">Module</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">extra_repr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;kernel_size=</span><span class="si">{}</span><span class="s1">, stride=</span><span class="si">{}</span><span class="s1">, padding=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span>
        <span class="p">)</span>


<div class="viewcode-block" id="MaxUnpool1d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.MaxUnpool1d">[docs]</a><span class="k">class</span> <span class="nc">MaxUnpool1d</span><span class="p">(</span><span class="n">_MaxUnpoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Computes a partial inverse of :class:`MaxPool1d`.</span>

<span class="sd">    :class:`MaxPool1d` is not fully invertible, since the non-maximal values are lost.</span>

<span class="sd">    :class:`MaxUnpool1d` takes in as input the output of :class:`MaxPool1d`</span>
<span class="sd">    including the indices of the maximal values and computes a partial inverse</span>
<span class="sd">    in which all non-maximal values are set to zero.</span>

<span class="sd">    .. note:: :class:`MaxPool1d` can map several input sizes to the same output</span>
<span class="sd">              sizes. Hence, the inversion process can get ambiguous.</span>
<span class="sd">              To accommodate this, you can provide the needed output size</span>
<span class="sd">              as an additional argument :attr:`output_size` in the forward call.</span>
<span class="sd">              See the Inputs and Example below.</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size (int or tuple): Size of the max pooling window.</span>
<span class="sd">        stride (int or tuple): Stride of the max pooling window.</span>
<span class="sd">            It is set to :attr:`kernel_size` by default.</span>
<span class="sd">        padding (int or tuple): Padding that was added to the input</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - `input`: the input Tensor to invert</span>
<span class="sd">        - `indices`: the indices given out by :class:`~torch.nn.MaxPool1d`</span>
<span class="sd">        - `output_size` (optional): the targeted output size</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, H_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, H_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              H_{out} = (H_{in} - 1) \times \text{stride}[0] - 2 \times \text{padding}[0] + \text{kernel\_size}[0]</span>

<span class="sd">          or as given by :attr:`output_size` in the call operator</span>

<span class="sd">    Example::</span>

<span class="sd">        &gt;&gt;&gt; pool = nn.MaxPool1d(2, stride=2, return_indices=True)</span>
<span class="sd">        &gt;&gt;&gt; unpool = nn.MaxUnpool1d(2, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.tensor([[[1., 2, 3, 4, 5, 6, 7, 8]]])</span>
<span class="sd">        &gt;&gt;&gt; output, indices = pool(input)</span>
<span class="sd">        &gt;&gt;&gt; unpool(output, indices)</span>
<span class="sd">        tensor([[[ 0.,  2.,  0.,  4.,  0.,  6.,  0., 8.]]])</span>

<span class="sd">        &gt;&gt;&gt; # Example showcasing the use of output_size</span>
<span class="sd">        &gt;&gt;&gt; input = torch.tensor([[[1., 2, 3, 4, 5, 6, 7, 8, 9]]])</span>
<span class="sd">        &gt;&gt;&gt; output, indices = pool(input)</span>
<span class="sd">        &gt;&gt;&gt; unpool(output, indices, output_size=input.size())</span>
<span class="sd">        tensor([[[ 0.,  2.,  0.,  4.,  0.,  6.,  0., 8.,  0.]]])</span>

<span class="sd">        &gt;&gt;&gt; unpool(output, indices)</span>
<span class="sd">        tensor([[[ 0.,  2.,  0.,  4.,  0.,  6.,  0., 8.]]])</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">stride</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">padding</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">MaxUnpool1d</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">_single</span><span class="p">(</span><span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stride</span> <span class="o">=</span> <span class="n">_single</span><span class="p">(</span><span class="n">stride</span> <span class="ow">or</span> <span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="n">_single</span><span class="p">(</span><span class="n">padding</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">output_size</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="c1"># type: (Tensor, Tensor, Optional[List[int]]) -&gt; Tensor</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">max_unpool1d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span>
                              <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">,</span> <span class="n">output_size</span><span class="p">)</span></div>


<div class="viewcode-block" id="MaxUnpool2d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.MaxUnpool2d">[docs]</a><span class="k">class</span> <span class="nc">MaxUnpool2d</span><span class="p">(</span><span class="n">_MaxUnpoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Computes a partial inverse of :class:`MaxPool2d`.</span>

<span class="sd">    :class:`MaxPool2d` is not fully invertible, since the non-maximal values are lost.</span>

<span class="sd">    :class:`MaxUnpool2d` takes in as input the output of :class:`MaxPool2d`</span>
<span class="sd">    including the indices of the maximal values and computes a partial inverse</span>
<span class="sd">    in which all non-maximal values are set to zero.</span>

<span class="sd">    .. note:: :class:`MaxPool2d` can map several input sizes to the same output</span>
<span class="sd">              sizes. Hence, the inversion process can get ambiguous.</span>
<span class="sd">              To accommodate this, you can provide the needed output size</span>
<span class="sd">              as an additional argument :attr:`output_size` in the forward call.</span>
<span class="sd">              See the Inputs and Example below.</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size (int or tuple): Size of the max pooling window.</span>
<span class="sd">        stride (int or tuple): Stride of the max pooling window.</span>
<span class="sd">            It is set to :attr:`kernel_size` by default.</span>
<span class="sd">        padding (int or tuple): Padding that was added to the input</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - `input`: the input Tensor to invert</span>
<span class="sd">        - `indices`: the indices given out by :class:`~torch.nn.MaxPool2d`</span>
<span class="sd">        - `output_size` (optional): the targeted output size</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, H_{in}, W_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, H_{out}, W_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">            H_{out} = (H_{in} - 1) \times \text{stride[0]} - 2 \times \text{padding[0]} + \text{kernel\_size[0]}</span>

<span class="sd">          .. math::</span>
<span class="sd">            W_{out} = (W_{in} - 1) \times \text{stride[1]} - 2 \times \text{padding[1]} + \text{kernel\_size[1]}</span>

<span class="sd">          or as given by :attr:`output_size` in the call operator</span>

<span class="sd">    Example::</span>

<span class="sd">        &gt;&gt;&gt; pool = nn.MaxPool2d(2, stride=2, return_indices=True)</span>
<span class="sd">        &gt;&gt;&gt; unpool = nn.MaxUnpool2d(2, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.tensor([[[[ 1.,  2,  3,  4],</span>
<span class="sd">                                    [ 5,  6,  7,  8],</span>
<span class="sd">                                    [ 9, 10, 11, 12],</span>
<span class="sd">                                    [13, 14, 15, 16]]]])</span>
<span class="sd">        &gt;&gt;&gt; output, indices = pool(input)</span>
<span class="sd">        &gt;&gt;&gt; unpool(output, indices)</span>
<span class="sd">        tensor([[[[  0.,   0.,   0.,   0.],</span>
<span class="sd">                  [  0.,   6.,   0.,   8.],</span>
<span class="sd">                  [  0.,   0.,   0.,   0.],</span>
<span class="sd">                  [  0.,  14.,   0.,  16.]]]])</span>

<span class="sd">        &gt;&gt;&gt; # specify a different output size than input size</span>
<span class="sd">        &gt;&gt;&gt; unpool(output, indices, output_size=torch.Size([1, 1, 5, 5]))</span>
<span class="sd">        tensor([[[[  0.,   0.,   0.,   0.,   0.],</span>
<span class="sd">                  [  6.,   0.,   8.,   0.,   0.],</span>
<span class="sd">                  [  0.,   0.,   0.,  14.,   0.],</span>
<span class="sd">                  [ 16.,   0.,   0.,   0.,   0.],</span>
<span class="sd">                  [  0.,   0.,   0.,   0.,   0.]]]])</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">stride</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">padding</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">MaxUnpool2d</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">_pair</span><span class="p">(</span><span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stride</span> <span class="o">=</span> <span class="n">_pair</span><span class="p">(</span><span class="n">stride</span> <span class="ow">or</span> <span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="n">_pair</span><span class="p">(</span><span class="n">padding</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">output_size</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="c1"># type: (Tensor, Tensor, Optional[List[int]]) -&gt; Tensor</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">max_unpool2d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span>
                              <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">,</span> <span class="n">output_size</span><span class="p">)</span></div>


<div class="viewcode-block" id="MaxUnpool3d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.MaxUnpool3d">[docs]</a><span class="k">class</span> <span class="nc">MaxUnpool3d</span><span class="p">(</span><span class="n">_MaxUnpoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Computes a partial inverse of :class:`MaxPool3d`.</span>

<span class="sd">    :class:`MaxPool3d` is not fully invertible, since the non-maximal values are lost.</span>
<span class="sd">    :class:`MaxUnpool3d` takes in as input the output of :class:`MaxPool3d`</span>
<span class="sd">    including the indices of the maximal values and computes a partial inverse</span>
<span class="sd">    in which all non-maximal values are set to zero.</span>

<span class="sd">    .. note:: :class:`MaxPool3d` can map several input sizes to the same output</span>
<span class="sd">              sizes. Hence, the inversion process can get ambiguous.</span>
<span class="sd">              To accommodate this, you can provide the needed output size</span>
<span class="sd">              as an additional argument :attr:`output_size` in the forward call.</span>
<span class="sd">              See the Inputs section below.</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size (int or tuple): Size of the max pooling window.</span>
<span class="sd">        stride (int or tuple): Stride of the max pooling window.</span>
<span class="sd">            It is set to :attr:`kernel_size` by default.</span>
<span class="sd">        padding (int or tuple): Padding that was added to the input</span>

<span class="sd">    Inputs:</span>
<span class="sd">        - `input`: the input Tensor to invert</span>
<span class="sd">        - `indices`: the indices given out by :class:`~torch.nn.MaxPool3d`</span>
<span class="sd">        - `output_size` (optional): the targeted output size</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, D_{in}, H_{in}, W_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, D_{out}, H_{out}, W_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              D_{out} = (D_{in} - 1) \times \text{stride[0]} - 2 \times \text{padding[0]} + \text{kernel\_size[0]}</span>

<span class="sd">          .. math::</span>
<span class="sd">              H_{out} = (H_{in} - 1) \times \text{stride[1]} - 2 \times \text{padding[1]} + \text{kernel\_size[1]}</span>

<span class="sd">          .. math::</span>
<span class="sd">              W_{out} = (W_{in} - 1) \times \text{stride[2]} - 2 \times \text{padding[2]} + \text{kernel\_size[2]}</span>

<span class="sd">          or as given by :attr:`output_size` in the call operator</span>

<span class="sd">    Example::</span>

<span class="sd">        &gt;&gt;&gt; # pool of square window of size=3, stride=2</span>
<span class="sd">        &gt;&gt;&gt; pool = nn.MaxPool3d(3, stride=2, return_indices=True)</span>
<span class="sd">        &gt;&gt;&gt; unpool = nn.MaxUnpool3d(3, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; output, indices = pool(torch.randn(20, 16, 51, 33, 15))</span>
<span class="sd">        &gt;&gt;&gt; unpooled_output = unpool(output, indices)</span>
<span class="sd">        &gt;&gt;&gt; unpooled_output.size()</span>
<span class="sd">        torch.Size([20, 16, 51, 33, 15])</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">stride</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">padding</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">MaxUnpool3d</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">_triple</span><span class="p">(</span><span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stride</span> <span class="o">=</span> <span class="n">_triple</span><span class="p">(</span><span class="n">stride</span> <span class="ow">or</span> <span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="n">_triple</span><span class="p">(</span><span class="n">padding</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">output_size</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="c1"># type: (Tensor, Tensor, Optional[List[int]]) -&gt; Tensor</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">max_unpool3d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span>
                              <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">,</span> <span class="n">output_size</span><span class="p">)</span></div>


<span class="k">class</span> <span class="nc">_AvgPoolNd</span><span class="p">(</span><span class="n">Module</span><span class="p">):</span>
    <span class="n">__constants__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;kernel_size&#39;</span><span class="p">,</span> <span class="s1">&#39;stride&#39;</span><span class="p">,</span> <span class="s1">&#39;padding&#39;</span><span class="p">,</span> <span class="s1">&#39;ceil_mode&#39;</span><span class="p">,</span> <span class="s1">&#39;count_include_pad&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">extra_repr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;kernel_size=</span><span class="si">{}</span><span class="s1">, stride=</span><span class="si">{}</span><span class="s1">, padding=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span>
        <span class="p">)</span>


<div class="viewcode-block" id="AvgPool1d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.AvgPool1d">[docs]</a><span class="k">class</span> <span class="nc">AvgPool1d</span><span class="p">(</span><span class="n">_AvgPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 1D average pooling over an input signal composed of several</span>
<span class="sd">    input planes.</span>

<span class="sd">    In the simplest case, the output value of the layer with input size :math:`(N, C, L)`,</span>
<span class="sd">    output :math:`(N, C, L_{out})` and :attr:`kernel_size` :math:`k`</span>
<span class="sd">    can be precisely described as:</span>

<span class="sd">    .. math::</span>

<span class="sd">        \text{out}(N_i, C_j, l) = \frac{1}{k} \sum_{m=0}^{k-1}</span>
<span class="sd">                               \text{input}(N_i, C_j, \text{stride} \times l + m)</span>

<span class="sd">    If :attr:`padding` is non-zero, then the input is implicitly zero-padded on both sides</span>
<span class="sd">    for :attr:`padding` number of points.</span>

<span class="sd">    The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding` can each be</span>
<span class="sd">    an ``int`` or a one-element tuple.</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: the size of the window</span>
<span class="sd">        stride: the stride of the window. Default value is :attr:`kernel_size`</span>
<span class="sd">        padding: implicit zero padding to be added on both sides</span>
<span class="sd">        ceil_mode: when True, will use `ceil` instead of `floor` to compute the output shape</span>
<span class="sd">        count_include_pad: when True, will include the zero-padding in the averaging calculation</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, L_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, L_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              L_{out} = \left\lfloor \frac{L_{in} +</span>
<span class="sd">              2 \times \text{padding} - \text{kernel\_size}}{\text{stride}} + 1\right\rfloor</span>

<span class="sd">    Examples::</span>

<span class="sd">        &gt;&gt;&gt; # pool with window of size=3, stride=2</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AvgPool1d(3, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; m(torch.tensor([[[1.,2,3,4,5,6,7]]]))</span>
<span class="sd">        tensor([[[ 2.,  4.,  6.]]])</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">stride</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">padding</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">ceil_mode</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">count_include_pad</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">AvgPool1d</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">_single</span><span class="p">(</span><span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stride</span> <span class="o">=</span> <span class="n">_single</span><span class="p">(</span><span class="n">stride</span> <span class="k">if</span> <span class="n">stride</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="n">_single</span><span class="p">(</span><span class="n">padding</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span> <span class="o">=</span> <span class="n">ceil_mode</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">count_include_pad</span> <span class="o">=</span> <span class="n">count_include_pad</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">avg_pool1d</span><span class="p">(</span>
            <span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">count_include_pad</span><span class="p">)</span></div>


<div class="viewcode-block" id="AvgPool2d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.AvgPool2d">[docs]</a><span class="k">class</span> <span class="nc">AvgPool2d</span><span class="p">(</span><span class="n">_AvgPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 2D average pooling over an input signal composed of several input</span>
<span class="sd">    planes.</span>

<span class="sd">    In the simplest case, the output value of the layer with input size :math:`(N, C, H, W)`,</span>
<span class="sd">    output :math:`(N, C, H_{out}, W_{out})` and :attr:`kernel_size` :math:`(kH, kW)`</span>
<span class="sd">    can be precisely described as:</span>

<span class="sd">    .. math::</span>

<span class="sd">        out(N_i, C_j, h, w)  = \frac{1}{kH * kW} \sum_{m=0}^{kH-1} \sum_{n=0}^{kW-1}</span>
<span class="sd">                               input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)</span>

<span class="sd">    If :attr:`padding` is non-zero, then the input is implicitly zero-padded on both sides</span>
<span class="sd">    for :attr:`padding` number of points.</span>

<span class="sd">    The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding` can either be:</span>

<span class="sd">        - a single ``int`` -- in which case the same value is used for the height and width dimension</span>
<span class="sd">        - a ``tuple`` of two ints -- in which case, the first `int` is used for the height dimension,</span>
<span class="sd">          and the second `int` for the width dimension</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: the size of the window</span>
<span class="sd">        stride: the stride of the window. Default value is :attr:`kernel_size`</span>
<span class="sd">        padding: implicit zero padding to be added on both sides</span>
<span class="sd">        ceil_mode: when True, will use `ceil` instead of `floor` to compute the output shape</span>
<span class="sd">        count_include_pad: when True, will include the zero-padding in the averaging calculation</span>
<span class="sd">        divisor_override: if specified, it will be used as divisor, otherwise attr:`kernel_size` will be used</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, H_{in}, W_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, H_{out}, W_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              H_{out} = \left\lfloor\frac{H_{in}  + 2 \times \text{padding}[0] -</span>
<span class="sd">                \text{kernel\_size}[0]}{\text{stride}[0]} + 1\right\rfloor</span>

<span class="sd">          .. math::</span>
<span class="sd">              W_{out} = \left\lfloor\frac{W_{in}  + 2 \times \text{padding}[1] -</span>
<span class="sd">                \text{kernel\_size}[1]}{\text{stride}[1]} + 1\right\rfloor</span>

<span class="sd">    Examples::</span>

<span class="sd">        &gt;&gt;&gt; # pool of square window of size=3, stride=2</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AvgPool2d(3, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; # pool of non-square window</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AvgPool2d((3, 2), stride=(2, 1))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(20, 16, 50, 32)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">__constants__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;kernel_size&#39;</span><span class="p">,</span> <span class="s1">&#39;stride&#39;</span><span class="p">,</span> <span class="s1">&#39;padding&#39;</span><span class="p">,</span> <span class="s1">&#39;ceil_mode&#39;</span><span class="p">,</span> <span class="s1">&#39;count_include_pad&#39;</span><span class="p">,</span> <span class="s1">&#39;divisor_override&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">stride</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">padding</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">ceil_mode</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">count_include_pad</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">divisor_override</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">AvgPool2d</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">kernel_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stride</span> <span class="o">=</span> <span class="n">stride</span> <span class="ow">or</span> <span class="n">kernel_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="n">padding</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span> <span class="o">=</span> <span class="n">ceil_mode</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">count_include_pad</span> <span class="o">=</span> <span class="n">count_include_pad</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">divisor_override</span> <span class="o">=</span> <span class="n">divisor_override</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">avg_pool2d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">count_include_pad</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">divisor_override</span><span class="p">)</span></div>


<div class="viewcode-block" id="AvgPool3d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.AvgPool3d">[docs]</a><span class="k">class</span> <span class="nc">AvgPool3d</span><span class="p">(</span><span class="n">_AvgPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 3D average pooling over an input signal composed of several input</span>
<span class="sd">    planes.</span>

<span class="sd">    In the simplest case, the output value of the layer with input size :math:`(N, C, D, H, W)`,</span>
<span class="sd">    output :math:`(N, C, D_{out}, H_{out}, W_{out})` and :attr:`kernel_size` :math:`(kD, kH, kW)`</span>
<span class="sd">    can be precisely described as:</span>

<span class="sd">    .. math::</span>
<span class="sd">        \begin{aligned}</span>
<span class="sd">            \text{out}(N_i, C_j, d, h, w) ={} &amp; \sum_{k=0}^{kD-1} \sum_{m=0}^{kH-1} \sum_{n=0}^{kW-1} \\</span>
<span class="sd">                                              &amp; \frac{\text{input}(N_i, C_j, \text{stride}[0] \times d + k,</span>
<span class="sd">                                                      \text{stride}[1] \times h + m, \text{stride}[2] \times w + n)}</span>
<span class="sd">                                                     {kD \times kH \times kW}</span>
<span class="sd">        \end{aligned}</span>

<span class="sd">    If :attr:`padding` is non-zero, then the input is implicitly zero-padded on all three sides</span>
<span class="sd">    for :attr:`padding` number of points.</span>

<span class="sd">    The parameters :attr:`kernel_size`, :attr:`stride` can either be:</span>

<span class="sd">        - a single ``int`` -- in which case the same value is used for the depth, height and width dimension</span>
<span class="sd">        - a ``tuple`` of three ints -- in which case, the first `int` is used for the depth dimension,</span>
<span class="sd">          the second `int` for the height dimension and the third `int` for the width dimension</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: the size of the window</span>
<span class="sd">        stride: the stride of the window. Default value is :attr:`kernel_size`</span>
<span class="sd">        padding: implicit zero padding to be added on all three sides</span>
<span class="sd">        ceil_mode: when True, will use `ceil` instead of `floor` to compute the output shape</span>
<span class="sd">        count_include_pad: when True, will include the zero-padding in the averaging calculation</span>
<span class="sd">        divisor_override: if specified, it will be used as divisor, otherwise attr:`kernel_size` will be used</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, D_{in}, H_{in}, W_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, D_{out}, H_{out}, W_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              D_{out} = \left\lfloor\frac{D_{in} + 2 \times \text{padding}[0] -</span>
<span class="sd">                    \text{kernel\_size}[0]}{\text{stride}[0]} + 1\right\rfloor</span>

<span class="sd">          .. math::</span>
<span class="sd">              H_{out} = \left\lfloor\frac{H_{in} + 2 \times \text{padding}[1] -</span>
<span class="sd">                    \text{kernel\_size}[1]}{\text{stride}[1]} + 1\right\rfloor</span>

<span class="sd">          .. math::</span>
<span class="sd">              W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] -</span>
<span class="sd">                    \text{kernel\_size}[2]}{\text{stride}[2]} + 1\right\rfloor</span>

<span class="sd">    Examples::</span>

<span class="sd">        &gt;&gt;&gt; # pool of square window of size=3, stride=2</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AvgPool3d(3, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; # pool of non-square window</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AvgPool3d((3, 2, 2), stride=(2, 1, 2))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(20, 16, 50,44, 31)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">__constants__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;kernel_size&#39;</span><span class="p">,</span> <span class="s1">&#39;stride&#39;</span><span class="p">,</span> <span class="s1">&#39;padding&#39;</span><span class="p">,</span> <span class="s1">&#39;ceil_mode&#39;</span><span class="p">,</span> <span class="s1">&#39;count_include_pad&#39;</span><span class="p">,</span> <span class="s1">&#39;divisor_override&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">stride</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">padding</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">ceil_mode</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">count_include_pad</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">divisor_override</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">AvgPool3d</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">kernel_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stride</span> <span class="o">=</span> <span class="n">stride</span> <span class="ow">or</span> <span class="n">kernel_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="n">padding</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span> <span class="o">=</span> <span class="n">ceil_mode</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">count_include_pad</span> <span class="o">=</span> <span class="n">count_include_pad</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">divisor_override</span> <span class="o">=</span> <span class="n">divisor_override</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">avg_pool3d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">count_include_pad</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">divisor_override</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__setstate__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">AvgPool3d</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__setstate__</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s1">&#39;padding&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s1">&#39;ceil_mode&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s1">&#39;count_include_pad&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span></div>


<div class="viewcode-block" id="FractionalMaxPool2d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.FractionalMaxPool2d">[docs]</a><span class="k">class</span> <span class="nc">FractionalMaxPool2d</span><span class="p">(</span><span class="n">Module</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 2D fractional max pooling over an input signal composed of several input planes.</span>

<span class="sd">    Fractional MaxPooling is described in detail in the paper `Fractional MaxPooling`_ by Ben Graham</span>

<span class="sd">    The max-pooling operation is applied in :math:`kH \times kW` regions by a stochastic</span>
<span class="sd">    step size determined by the target output size.</span>
<span class="sd">    The number of output features is equal to the number of input planes.</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: the size of the window to take a max over.</span>
<span class="sd">                     Can be a single number k (for a square kernel of k x k) or a tuple `(kh, kw)`</span>
<span class="sd">        output_size: the target output size of the image of the form `oH x oW`.</span>
<span class="sd">                     Can be a tuple `(oH, oW)` or a single number oH for a square image `oH x oH`</span>
<span class="sd">        output_ratio: If one wants to have an output size as a ratio of the input size, this option can be given.</span>
<span class="sd">                      This has to be a number or tuple in the range (0, 1)</span>
<span class="sd">        return_indices: if ``True``, will return the indices along with the outputs.</span>
<span class="sd">                        Useful to pass to :meth:`nn.MaxUnpool2d`. Default: ``False``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; # pool of square window of size=3, and target output size 13x12</span>
<span class="sd">        &gt;&gt;&gt; m = nn.FractionalMaxPool2d(3, output_size=(13, 12))</span>
<span class="sd">        &gt;&gt;&gt; # pool of square window and target output size being half of input image size</span>
<span class="sd">        &gt;&gt;&gt; m = nn.FractionalMaxPool2d(3, output_ratio=(0.5, 0.5))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(20, 16, 50, 32)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    .. _Fractional MaxPooling:</span>
<span class="sd">        http://arxiv.org/abs/1412.6071</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">__constants__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;kernel_size&#39;</span><span class="p">,</span> <span class="s1">&#39;return_indices&#39;</span><span class="p">,</span> <span class="s1">&#39;output_size&#39;</span><span class="p">,</span>
                     <span class="s1">&#39;output_ratio&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">output_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">output_ratio</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">return_indices</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">_random_samples</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">FractionalMaxPool2d</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">_pair</span><span class="p">(</span><span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span> <span class="o">=</span> <span class="n">return_indices</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">register_buffer</span><span class="p">(</span><span class="s1">&#39;_random_samples&#39;</span><span class="p">,</span> <span class="n">_random_samples</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span> <span class="o">=</span> <span class="n">_pair</span><span class="p">(</span><span class="n">output_size</span><span class="p">)</span> <span class="k">if</span> <span class="n">output_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span> <span class="o">=</span> <span class="n">_pair</span><span class="p">(</span><span class="n">output_ratio</span><span class="p">)</span> <span class="k">if</span> <span class="n">output_ratio</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">output_size</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">output_ratio</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;FractionalMaxPool2d requires specifying either &quot;</span>
                             <span class="s2">&quot;an output size, or a pooling ratio&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">output_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">output_ratio</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;only one of output_size and output_ratio may be specified&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="mi">0</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="mi">0</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;output_ratio must be between 0 and 1 (got </span><span class="si">{}</span><span class="s2">)&quot;</span>
                                 <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">output_ratio</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">fractional_max_pool2d</span><span class="p">(</span>
            <span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span><span class="p">,</span>
            <span class="n">_random_samples</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_random_samples</span><span class="p">)</span></div>


<span class="k">class</span> <span class="nc">FractionalMaxPool3d</span><span class="p">(</span><span class="n">Module</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 3D fractional max pooling over an input signal composed of several input planes.</span>

<span class="sd">    Fractional MaxPooling is described in detail in the paper `Fractional MaxPooling`_ by Ben Graham</span>

<span class="sd">    The max-pooling operation is applied in :math:`kTxkHxkW` regions by a stochastic</span>
<span class="sd">    step size determined by the target output size.</span>
<span class="sd">    The number of output features is equal to the number of input planes.</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: the size of the window to take a max over.</span>
<span class="sd">                     Can be a single number k (for a square kernel of k x k x k) or a tuple `(kt x kh x kw)`</span>
<span class="sd">        output_size: the target output size of the image of the form `oT x oH x oW`.</span>
<span class="sd">                     Can be a tuple `(oT, oH, oW)` or a single number oH for a square image `oH x oH x oH`</span>
<span class="sd">        output_ratio: If one wants to have an output size as a ratio of the input size, this option can be given.</span>
<span class="sd">                      This has to be a number or tuple in the range (0, 1)</span>
<span class="sd">        return_indices: if ``True``, will return the indices along with the outputs.</span>
<span class="sd">                        Useful to pass to :meth:`nn.MaxUnpool3d`. Default: ``False``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; # pool of cubic window of size=3, and target output size 13x12x11</span>
<span class="sd">        &gt;&gt;&gt; m = nn.FractionalMaxPool3d(3, output_size=(13, 12, 11))</span>
<span class="sd">        &gt;&gt;&gt; # pool of cubic window and target output size being half of input size</span>
<span class="sd">        &gt;&gt;&gt; m = nn.FractionalMaxPool3d(3, output_ratio=(0.5, 0.5, 0.5))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(20, 16, 50, 32, 16)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    .. _Fractional MaxPooling:</span>
<span class="sd">        http://arxiv.org/abs/1412.6071</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">__constants__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;kernel_size&#39;</span><span class="p">,</span> <span class="s1">&#39;return_indices&#39;</span><span class="p">,</span> <span class="s1">&#39;output_size&#39;</span><span class="p">,</span>
                     <span class="s1">&#39;output_ratio&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">output_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">output_ratio</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">return_indices</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">_random_samples</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">FractionalMaxPool3d</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">_triple</span><span class="p">(</span><span class="n">kernel_size</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span> <span class="o">=</span> <span class="n">return_indices</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">register_buffer</span><span class="p">(</span><span class="s1">&#39;_random_samples&#39;</span><span class="p">,</span> <span class="n">_random_samples</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span> <span class="o">=</span> <span class="n">_triple</span><span class="p">(</span><span class="n">output_size</span><span class="p">)</span> <span class="k">if</span> <span class="n">output_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span> <span class="o">=</span> <span class="n">_triple</span><span class="p">(</span><span class="n">output_ratio</span><span class="p">)</span> <span class="k">if</span> <span class="n">output_ratio</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">output_size</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">output_ratio</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;FractionalMaxPool3d requires specifying either &quot;</span>
                             <span class="s2">&quot;an output size, or a pooling ratio&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">output_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">output_ratio</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;only one of output_size and output_ratio may be specified&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="mi">0</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="mi">0</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="mi">0</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;output_ratio must be between 0 and 1 (got </span><span class="si">{}</span><span class="s2">)&quot;</span>
                                 <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">output_ratio</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">fractional_max_pool3d</span><span class="p">(</span>
            <span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_ratio</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span><span class="p">,</span>
            <span class="n">_random_samples</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_random_samples</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">_LPPoolNd</span><span class="p">(</span><span class="n">Module</span><span class="p">):</span>
    <span class="n">__constants__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;norm_type&#39;</span><span class="p">,</span> <span class="s1">&#39;kernel_size&#39;</span><span class="p">,</span> <span class="s1">&#39;stride&#39;</span><span class="p">,</span> <span class="s1">&#39;ceil_mode&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">norm_type</span><span class="p">,</span> <span class="n">kernel_size</span><span class="p">,</span> <span class="n">stride</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">ceil_mode</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">_LPPoolNd</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">norm_type</span> <span class="o">=</span> <span class="n">norm_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span> <span class="o">=</span> <span class="n">kernel_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stride</span> <span class="o">=</span> <span class="n">stride</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span> <span class="o">=</span> <span class="n">ceil_mode</span>

    <span class="k">def</span> <span class="nf">extra_repr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;norm_type=</span><span class="si">{norm_type}</span><span class="s1">, kernel_size=</span><span class="si">{kernel_size}</span><span class="s1">, stride=</span><span class="si">{stride}</span><span class="s1">, &#39;</span> \
            <span class="s1">&#39;ceil_mode=</span><span class="si">{ceil_mode}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">)</span>


<div class="viewcode-block" id="LPPool1d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.LPPool1d">[docs]</a><span class="k">class</span> <span class="nc">LPPool1d</span><span class="p">(</span><span class="n">_LPPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 1D power-average pooling over an input signal composed of several input</span>
<span class="sd">    planes.</span>

<span class="sd">    On each window, the function computed is:</span>

<span class="sd">    .. math::</span>
<span class="sd">        f(X) = \sqrt[p]{\sum_{x \in X} x^{p}}</span>

<span class="sd">    - At p = :math:`\infty`, one gets Max Pooling</span>
<span class="sd">    - At p = 1, one gets Sum Pooling (which is proportional to Average Pooling)</span>

<span class="sd">    .. note:: If the sum to the power of `p` is zero, the gradient of this function is</span>
<span class="sd">              not defined. This implementation will set the gradient to zero in this case.</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: a single int, the size of the window</span>
<span class="sd">        stride: a single int, the stride of the window. Default value is :attr:`kernel_size`</span>
<span class="sd">        ceil_mode: when True, will use `ceil` instead of `floor` to compute the output shape</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, L_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, L_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              L_{out} = \left\lfloor\frac{L_{in} - \text{kernel\_size}}{\text{stride}} + 1\right\rfloor</span>

<span class="sd">    Examples::</span>
<span class="sd">        &gt;&gt;&gt; # power-2 pool of window of length 3, with stride 2.</span>
<span class="sd">        &gt;&gt;&gt; m = nn.LPPool1d(2, 3, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(20, 16, 50)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">lp_pool1d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">norm_type</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span>
                           <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span><span class="p">)</span></div>


<div class="viewcode-block" id="LPPool2d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.LPPool2d">[docs]</a><span class="k">class</span> <span class="nc">LPPool2d</span><span class="p">(</span><span class="n">_LPPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 2D power-average pooling over an input signal composed of several input</span>
<span class="sd">    planes.</span>

<span class="sd">    On each window, the function computed is:</span>

<span class="sd">    .. math::</span>
<span class="sd">        f(X) = \sqrt[p]{\sum_{x \in X} x^{p}}</span>

<span class="sd">    - At p = :math:`\infty`, one gets Max Pooling</span>
<span class="sd">    - At p = 1, one gets Sum Pooling (which is proportional to average pooling)</span>

<span class="sd">    The parameters :attr:`kernel_size`, :attr:`stride` can either be:</span>

<span class="sd">        - a single ``int`` -- in which case the same value is used for the height and width dimension</span>
<span class="sd">        - a ``tuple`` of two ints -- in which case, the first `int` is used for the height dimension,</span>
<span class="sd">          and the second `int` for the width dimension</span>

<span class="sd">    .. note:: If the sum to the power of `p` is zero, the gradient of this function is</span>
<span class="sd">              not defined. This implementation will set the gradient to zero in this case.</span>

<span class="sd">    Args:</span>
<span class="sd">        kernel_size: the size of the window</span>
<span class="sd">        stride: the stride of the window. Default value is :attr:`kernel_size`</span>
<span class="sd">        ceil_mode: when True, will use `ceil` instead of `floor` to compute the output shape</span>

<span class="sd">    Shape:</span>
<span class="sd">        - Input: :math:`(N, C, H_{in}, W_{in})`</span>
<span class="sd">        - Output: :math:`(N, C, H_{out}, W_{out})`, where</span>

<span class="sd">          .. math::</span>
<span class="sd">              H_{out} = \left\lfloor\frac{H_{in} - \text{kernel\_size}[0]}{\text{stride}[0]} + 1\right\rfloor</span>

<span class="sd">          .. math::</span>
<span class="sd">              W_{out} = \left\lfloor\frac{W_{in} - \text{kernel\_size}[1]}{\text{stride}[1]} + 1\right\rfloor</span>

<span class="sd">    Examples::</span>

<span class="sd">        &gt;&gt;&gt; # power-2 pool of square window of size=3, stride=2</span>
<span class="sd">        &gt;&gt;&gt; m = nn.LPPool2d(2, 3, stride=2)</span>
<span class="sd">        &gt;&gt;&gt; # pool of non-square window of power 1.2</span>
<span class="sd">        &gt;&gt;&gt; m = nn.LPPool2d(1.2, (3, 2), stride=(2, 1))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(20, 16, 50, 32)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">lp_pool2d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">norm_type</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">,</span>
                           <span class="bp">self</span><span class="o">.</span><span class="n">stride</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceil_mode</span><span class="p">)</span></div>


<span class="k">class</span> <span class="nc">_AdaptiveMaxPoolNd</span><span class="p">(</span><span class="n">Module</span><span class="p">):</span>
    <span class="n">__constants__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;output_size&#39;</span><span class="p">,</span> <span class="s1">&#39;return_indices&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output_size</span><span class="p">,</span> <span class="n">return_indices</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">_AdaptiveMaxPoolNd</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span> <span class="o">=</span> <span class="n">output_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span> <span class="o">=</span> <span class="n">return_indices</span>

    <span class="k">def</span> <span class="nf">extra_repr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;output_size=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">)</span>

<span class="c1"># FIXME (by @ssnl): Improve adaptive pooling docs: specify what the input and</span>
<span class="c1">#   output shapes are, and how the operation computes output.</span>


<div class="viewcode-block" id="AdaptiveMaxPool1d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.AdaptiveMaxPool1d">[docs]</a><span class="k">class</span> <span class="nc">AdaptiveMaxPool1d</span><span class="p">(</span><span class="n">_AdaptiveMaxPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 1D adaptive max pooling over an input signal composed of several input planes.</span>

<span class="sd">    The output size is H, for any input size.</span>
<span class="sd">    The number of output features is equal to the number of input planes.</span>

<span class="sd">    Args:</span>
<span class="sd">        output_size: the target output size H</span>
<span class="sd">        return_indices: if ``True``, will return the indices along with the outputs.</span>
<span class="sd">                        Useful to pass to nn.MaxUnpool1d. Default: ``False``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 5</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveMaxPool1d(5)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 8)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">adaptive_max_pool1d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span><span class="p">)</span></div>


<div class="viewcode-block" id="AdaptiveMaxPool2d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.AdaptiveMaxPool2d">[docs]</a><span class="k">class</span> <span class="nc">AdaptiveMaxPool2d</span><span class="p">(</span><span class="n">_AdaptiveMaxPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 2D adaptive max pooling over an input signal composed of several input planes.</span>

<span class="sd">    The output is of size H x W, for any input size.</span>
<span class="sd">    The number of output features is equal to the number of input planes.</span>

<span class="sd">    Args:</span>
<span class="sd">        output_size: the target output size of the image of the form H x W.</span>
<span class="sd">                     Can be a tuple (H, W) or a single H for a square image H x H.</span>
<span class="sd">                     H and W can be either a ``int``, or ``None`` which means the size will</span>
<span class="sd">                     be the same as that of the input.</span>
<span class="sd">        return_indices: if ``True``, will return the indices along with the outputs.</span>
<span class="sd">                        Useful to pass to nn.MaxUnpool2d. Default: ``False``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 5x7</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveMaxPool2d((5,7))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 8, 9)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 7x7 (square)</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveMaxPool2d(7)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 10, 9)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 10x7</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveMaxPool2d((None, 7))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 10, 9)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">adaptive_max_pool2d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span><span class="p">)</span></div>


<div class="viewcode-block" id="AdaptiveMaxPool3d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.AdaptiveMaxPool3d">[docs]</a><span class="k">class</span> <span class="nc">AdaptiveMaxPool3d</span><span class="p">(</span><span class="n">_AdaptiveMaxPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 3D adaptive max pooling over an input signal composed of several input planes.</span>

<span class="sd">    The output is of size D x H x W, for any input size.</span>
<span class="sd">    The number of output features is equal to the number of input planes.</span>

<span class="sd">    Args:</span>
<span class="sd">        output_size: the target output size of the image of the form D x H x W.</span>
<span class="sd">                     Can be a tuple (D, H, W) or a single D for a cube D x D x D.</span>
<span class="sd">                     D, H and W can be either a ``int``, or ``None`` which means the size will</span>
<span class="sd">                     be the same as that of the input.</span>

<span class="sd">        return_indices: if ``True``, will return the indices along with the outputs.</span>
<span class="sd">                        Useful to pass to nn.MaxUnpool3d. Default: ``False``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 5x7x9</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveMaxPool3d((5,7,9))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 8, 9, 10)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 7x7x7 (cube)</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveMaxPool3d(7)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 10, 9, 8)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 7x9x8</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveMaxPool3d((7, None, None))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 10, 9, 8)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">adaptive_max_pool3d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">return_indices</span><span class="p">)</span></div>


<span class="k">class</span> <span class="nc">_AdaptiveAvgPoolNd</span><span class="p">(</span><span class="n">Module</span><span class="p">):</span>
    <span class="n">__constants__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;output_size&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output_size</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">_AdaptiveAvgPoolNd</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span> <span class="o">=</span> <span class="n">output_size</span>

    <span class="k">def</span> <span class="nf">extra_repr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;output_size=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">)</span>


<div class="viewcode-block" id="AdaptiveAvgPool1d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.AdaptiveAvgPool1d">[docs]</a><span class="k">class</span> <span class="nc">AdaptiveAvgPool1d</span><span class="p">(</span><span class="n">_AdaptiveAvgPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 1D adaptive average pooling over an input signal composed of several input planes.</span>

<span class="sd">    The output size is H, for any input size.</span>
<span class="sd">    The number of output features is equal to the number of input planes.</span>

<span class="sd">    Args:</span>
<span class="sd">        output_size: the target output size H</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 5</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveAvgPool1d(5)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 8)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">adaptive_avg_pool1d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">)</span></div>


<div class="viewcode-block" id="AdaptiveAvgPool2d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.AdaptiveAvgPool2d">[docs]</a><span class="k">class</span> <span class="nc">AdaptiveAvgPool2d</span><span class="p">(</span><span class="n">_AdaptiveAvgPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 2D adaptive average pooling over an input signal composed of several input planes.</span>

<span class="sd">    The output is of size H x W, for any input size.</span>
<span class="sd">    The number of output features is equal to the number of input planes.</span>

<span class="sd">    Args:</span>
<span class="sd">        output_size: the target output size of the image of the form H x W.</span>
<span class="sd">                     Can be a tuple (H, W) or a single H for a square image H x H.</span>
<span class="sd">                     H and W can be either a ``int``, or ``None`` which means the size will</span>
<span class="sd">                     be the same as that of the input.</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 5x7</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveAvgPool2d((5,7))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 8, 9)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 7x7 (square)</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveAvgPool2d(7)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 10, 9)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 10x7</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveMaxPool2d((None, 7))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 10, 9)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">adaptive_avg_pool2d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">)</span></div>


<div class="viewcode-block" id="AdaptiveAvgPool3d"><a class="viewcode-back" href="../../../../nn.html#torch.nn.AdaptiveAvgPool3d">[docs]</a><span class="k">class</span> <span class="nc">AdaptiveAvgPool3d</span><span class="p">(</span><span class="n">_AdaptiveAvgPoolNd</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;Applies a 3D adaptive average pooling over an input signal composed of several input planes.</span>

<span class="sd">    The output is of size D x H x W, for any input size.</span>
<span class="sd">    The number of output features is equal to the number of input planes.</span>

<span class="sd">    Args:</span>
<span class="sd">        output_size: the target output size of the form D x H x W.</span>
<span class="sd">                     Can be a tuple (D, H, W) or a single number D for a cube D x D x D.</span>
<span class="sd">                     D, H and W can be either a ``int``, or ``None`` which means the size will</span>
<span class="sd">                     be the same as that of the input.</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 5x7x9</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveAvgPool3d((5,7,9))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 8, 9, 10)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 7x7x7 (cube)</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveAvgPool3d(7)</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 10, 9, 8)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>
<span class="sd">        &gt;&gt;&gt; # target output size of 7x9x8</span>
<span class="sd">        &gt;&gt;&gt; m = nn.AdaptiveMaxPool3d((7, None, None))</span>
<span class="sd">        &gt;&gt;&gt; input = torch.randn(1, 64, 10, 9, 8)</span>
<span class="sd">        &gt;&gt;&gt; output = m(input)</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">adaptive_avg_pool3d</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_size</span><span class="p">)</span></div>
</pre></div>

             </article>
             
            </div>
            <footer>
  

  

    <hr>

  

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, Torch Contributors.

    </p>
  </div>
    
      <div>
        Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
      </div>
     

</footer>

          </div>
        </div>

        <div class="pytorch-content-right" id="pytorch-content-right">
          <div class="pytorch-right-menu" id="pytorch-right-menu">
            <div class="pytorch-side-scroll" id="pytorch-side-scroll-right">
              
            </div>
          </div>
        </div>
      </section>
    </div>

  


  

     
       <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
         <script src="../../../../_static/jquery.js"></script>
         <script src="../../../../_static/underscore.js"></script>
         <script src="../../../../_static/doctools.js"></script>
         <script src="../../../../_static/language_data.js"></script>
     

  

  <script type="text/javascript" src="../../../../_static/js/vendor/popper.min.js"></script>
  <script type="text/javascript" src="../../../../_static/js/vendor/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script>
  <script type="text/javascript" src="../../../../_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>
 
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-90545585-1', 'auto');
  ga('send', 'pageview');

</script>

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-117752657-2"></script>

<script>
  window.dataLayer = window.dataLayer || [];

  function gtag(){dataLayer.push(arguments);}

  gtag('js', new Date());
  gtag('config', 'UA-117752657-2');
</script>

<img height="1" width="1" style="border-style:none;" alt="" src="https://www.googleadservices.com/pagead/conversion/795629140/?label=txkmCPmdtosBENSssfsC&amp;guid=ON&amp;script=0"/>


  <!-- Begin Footer -->

  <div class="container-fluid docs-tutorials-resources" id="docs-tutorials-resources">
    <div class="container">
      <div class="row">
        <div class="col-md-4 text-center">
          <h2>Docs</h2>
          <p>Access comprehensive developer documentation for PyTorch</p>
          <a class="with-right-arrow" href="https://pytorch.org/docs/stable/index.html">View Docs</a>
        </div>

        <div class="col-md-4 text-center">
          <h2>Tutorials</h2>
          <p>Get in-depth tutorials for beginners and advanced developers</p>
          <a class="with-right-arrow" href="https://pytorch.org/tutorials">View Tutorials</a>
        </div>

        <div class="col-md-4 text-center">
          <h2>Resources</h2>
          <p>Find development resources and get your questions answered</p>
          <a class="with-right-arrow" href="https://pytorch.org/resources">View Resources</a>
        </div>
      </div>
    </div>
  </div>

  <footer class="site-footer">
    <div class="container footer-container">
      <div class="footer-logo-wrapper">
        <a href="https://pytorch.org/" class="footer-logo"></a>
      </div>

      <div class="footer-links-wrapper">
        <div class="footer-links-col">
          <ul>
            <li class="list-title"><a href="https://pytorch.org/">PyTorch</a></li>
            <li><a href="https://pytorch.org/get-started">Get Started</a></li>
            <li><a href="https://pytorch.org/features">Features</a></li>
            <li><a href="https://pytorch.org/ecosystem">Ecosystem</a></li>
            <li><a href="https://pytorch.org/blog/">Blog</a></li>
            <li><a href="https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md">Contributing</a></li>
          </ul>
        </div>

        <div class="footer-links-col">
          <ul>
            <li class="list-title"><a href="https://pytorch.org/resources">Resources</a></li>
            <li><a href="https://pytorch.org/tutorials">Tutorials</a></li>
            <li><a href="https://pytorch.org/docs/stable/index.html">Docs</a></li>
            <li><a href="https://discuss.pytorch.org" target="_blank">Discuss</a></li>
            <li><a href="https://github.com/pytorch/pytorch/issues" target="_blank">Github Issues</a></li>
            <li><a href="https://pytorch.org/assets/brand-guidelines/PyTorch-Brand-Guidelines.pdf" target="_blank">Brand Guidelines</a></li>
          </ul>
        </div>

        <div class="footer-links-col follow-us-col">
          <ul>
            <li class="list-title">Stay Connected</li>
            <li>
              <div id="mc_embed_signup">
                <form
                  action="https://twitter.us14.list-manage.com/subscribe/post?u=75419c71fe0a935e53dfa4a3f&id=91d0dccd39"
                  method="post"
                  id="mc-embedded-subscribe-form"
                  name="mc-embedded-subscribe-form"
                  class="email-subscribe-form validate"
                  target="_blank"
                  novalidate>
                  <div id="mc_embed_signup_scroll" class="email-subscribe-form-fields-wrapper">
                    <div class="mc-field-group">
                      <label for="mce-EMAIL" style="display:none;">Email Address</label>
                      <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="Email Address">
                    </div>

                    <div id="mce-responses" class="clear">
                      <div class="response" id="mce-error-response" style="display:none"></div>
                      <div class="response" id="mce-success-response" style="display:none"></div>
                    </div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->

                    <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_75419c71fe0a935e53dfa4a3f_91d0dccd39" tabindex="-1" value=""></div>

                    <div class="clear">
                      <input type="submit" value="" name="subscribe" id="mc-embedded-subscribe" class="button email-subscribe-button">
                    </div>
                  </div>
                </form>
              </div>

            </li>
          </ul>

          <div class="footer-social-icons">
            <a href="https://www.facebook.com/pytorch" target="_blank" class="facebook"></a>
            <a href="https://twitter.com/pytorch" target="_blank" class="twitter"></a>
            <a href="https://www.youtube.com/pytorch" target="_blank" class="youtube"></a>
          </div>
        </div>
      </div>
    </div>
  </footer>

  <div class="cookie-banner-wrapper">
  <div class="container">
    <p class="gdpr-notice">To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: <a href="https://www.facebook.com/policies/cookies/">Cookies Policy</a>.</p>
    <img class="close-button" src="../../../../_static/images/pytorch-x.svg">
  </div>
</div>

  <!-- End Footer -->

  <!-- Begin Mobile Menu -->

  <div class="mobile-main-menu">
    <div class="container-fluid">
      <div class="container">
        <div class="mobile-main-menu-header-container">
          <a class="header-logo" href="https://pytorch.org/" aria-label="PyTorch"></a>
          <a class="main-menu-close-button" href="#" data-behavior="close-mobile-menu"></a>
        </div>
      </div>
    </div>

    <div class="mobile-main-menu-links-container">
      <div class="main-menu">
        <ul>
          <li>
            <a href="https://pytorch.org/get-started">Get Started</a>
          </li>

          <li>
            <a href="https://pytorch.org/features">Features</a>
          </li>

          <li>
            <a href="https://pytorch.org/ecosystem">Ecosystem</a>
          </li>

          <li>
            <a href="https://pytorch.org/mobile">Mobile</a>
          </li>

          <li>
            <a href="https://pytorch.org/hub">PyTorch Hub</a>
          </li>

          <li>
            <a href="https://pytorch.org/blog/">Blog</a>
          </li>

          <li>
            <a href="https://pytorch.org/tutorials">Tutorials</a>
          </li>

          <li class="active">
            <a href="https://pytorch.org/docs/stable/index.html">Docs</a>
          </li>

          <li>
            <a href="https://pytorch.org/resources">Resources</a>
          </li>

          <li>
            <a href="https://github.com/pytorch/pytorch">Github</a>
          </li>
        </ul>
      </div>
    </div>
  </div>

  <!-- End Mobile Menu -->

  <script type="text/javascript" src="../../../../_static/js/vendor/anchor.min.js"></script>

  <script type="text/javascript">
    $(document).ready(function() {
      mobileMenu.bind();
      mobileTOC.bind();
      pytorchAnchors.bind();
      sideMenus.bind();
      scrollToAnchor.bind();
      highlightNavigation.bind();
      mainMenuDropdown.bind();
      filterTags.bind();

      // Remove any empty p tags that Sphinx adds
      $("[data-tags='null']").remove();

      // Add class to links that have code blocks, since we cannot create links in code blocks
      $("article.pytorch-article a span.pre").each(function(e) {
        $(this).closest("a").addClass("has-code");
      });
    })
  </script>
</body>
</html>